<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="utf-8">
    <title>考勤记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
</head>
<body>
<input type="hidden" name="empid" th:value="${session.loginUser.getEmpId()}">
<table id="table-user" class="layui-table" lay-filter="table-user"></table>
<script type="text/html" id="currentTableBar">
</script>
<script type="text/html" id="toolbar">
    <form class="layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width:110px">员工姓名</label>
                <div class="layui-input-inline">
                    <select name="employeeid" class="layui-input"  >
                        <option value="">全部员工</option>
                        <option th:each="c:${attemp}" th:value="${c.id}" th:text="${c.empName}"></option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width:110px">出勤月份</label>
                <div class="layui-input-inline">
                    <select name="dakadateone" class="layui-input"  >
                        <option value="">全部月份</option>
                        <option th:each="d:${attdate}" th:value="${d.dakadateone}" th:text="${d.dakadateone}"></option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <button type="button" lay-submit class="layui-btn layui-btn-primary" lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
            </div>
        </div>

    </form>
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add"> 上班打卡 </button>
        <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="update"> 下班打卡 </button>
        <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="leave"> 请假 </button>
        <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="approval" th:if="${session.loginUser.getEmpId()==1}" shiro:hasPermission="kaoqin:pijia"> 批假 </button>
    </div>
</script>
<script src="../layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script th:inline="none">
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        let id=$(":input[name='empid']").val();
        table.render({
            elem: '#table-user',
            url: '/attendance/list?id='+id,
            method:'post',
            page: true,
            limits: [1,5,10,15],
            limit: 10,
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'employee', title: '员工名称',templet:function (d){return d.employee.empName}},
                {field: 'dakadate',title: '工作日期', sort: true},
                {field: 'shangbantime', title: '上班时间', sort: true},
                {field: 'xiabantime', title: '下班时间', sort: true},
                {field: 'statename', title: '状态', sort: true,templet:function (d){return d.statename.stateName}},
                {field: 'establishtime',title: '创建时间', sort: true},
            ]],
            toolbar:"#toolbar",
        });

        table.on('toolbar(table-user)', function (obj) {
            if (obj.event === 'add') {
                layer.confirm('正在打卡......',function(index){
                    var eid=$(":input[name='empid']").val();
                    $.post('/attendance/sdaka',{"empid":eid},function(res){
                        //响应
                        console.log(res);
                        if(res.data==="success"){
                            layer.msg(res.msg);
                            //重新加载表格
                            table.reload('table-user');
                        }
                    });
                    layer.close(index);
                })
            }else if (obj.event==='update'){
                layer.confirm('正在打卡......',function(index) {
                    var eid = $(":input[name='empid']").val();
                    $.post('/attendance/xdaka', {"empid": eid}, function (res) {
                        //响应
                        console.log(res);
                        if (res.data === "success") {
                            layer.msg(res.msg);
                            //重新加载表格
                            table.reload('table-user');
                        }
                    });
                    layer.close(index);
                })
            }else if (obj.event === 'approval') {
                var eid=$(":input[name='empid']").val();
                var index = layer.open({
                    title: '批假',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/attendance/approval?id='+eid,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }else  if (obj.event === 'leave') {
                var eid=$(":input[name='empid']").val();
                var index = layer.open({
                    title: '请假',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/attendance/qleave?id='+eid,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });
        form.on('submit(data-search-btn)',function(data){
            var result=JSON.stringify(data.field);
            console.log(result);
            //执行搜索重载
            table.reload('table-user',{
                page:{
                    curr:1
                },
                where:{
                    employeeid:data.field.employeeid,
                    dakadateone:data.field.dakadateone,
                }
            },'data');
            //阻止表单提交
            return false;
        })

    });
</script>
</body>
</html>